﻿using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace YArchitech.LIB
{
	public class YJKProcessTools
	{
		[DllImport("User32.dll")]
		private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

		[DllImport("User32.dll")]
		private static extern bool SetForegroundWindow(IntPtr hWnd);

		public static void HandleRunningInstance(Process instance)
		{
			YJKProcessTools.ShowWindowAsync(instance.MainWindowHandle, 1);
			YJKProcessTools.SetForegroundWindow(instance.MainWindowHandle);
		}

		public static void HandleRunningInstance(string fileName)
		{
			if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
			{
				return;
			}
			Process.Start(fileName);
		}

		public void ShowInTaskbarChange(System.Windows.Forms.Form form)
		{
			form.ShowInTaskbar = false;
		}

		private const int SW_SHOWNOMAL = 1;
	}
}
